import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'



Vue.use(Router)
const router = new Router({
    mode: 'hash',
    routes: [

        {
            path: '/',
            redirect: '/index',
            name: 'index',
            // component: resolve => (require(["@/views/index"], resolve)),
        },        
        {
            path: '/index',
            name: 'index',
            meta: {
                title: '首页'
            },
            component: resolve => (require(["@/views/index"], resolve)),//首页
        },
        {
            path: '/classify',
            name: 'classify',
            meta: {
                title: '分类'
            },
            component: resolve => (require(["@/views/classify"], resolve)),//分类
        },
        {
            path: '/send',
            name: 'send',
            meta: {
                title: '发布'
            },
            component: resolve => (require(["@/views/send"], resolve)),//发布-提交信息
        },
        // {
        //     path: '/adressList',
        //     name: 'customerAdressList',
        //     meta: {
        //         title: '地址簿'
        //     },
        //     component: resolve => (require(["@/views/adressList"], resolve)),//下单-地址簿
        // },
        // {
        //     path: '/adressEdit',
        //     name: 'customerAdressEdit',
        //     meta: {
        //         title: '编辑地址'
        //     },
        //     component: resolve => (require(["@/views/adressEdit"], resolve)),//下单-编辑地址
        // },        
         {
            path: '/sendList',
            name: 'sendList',
            meta: {
                title: '我的发布列表'
            },
            component: resolve => (require(["@/views/sendList"], resolve)),//发布列表
        },
        {
            path: '/orderList',
            name: 'orderList',
            meta: {
                title: '我买到的列表'
            },
            component: resolve => (require(["@/views/orderList"], resolve)),//我买到的列表
        },
        {
            path: '/systemList',
            name: 'systemList',
            meta: {
                title: '系统消息'
            },
            component: resolve => (require(["@/views/systemList"], resolve)),//系统消息
        },
        {
            path: '/chat/:avatar/:userId',
            name: 'chat',
            meta: {
                title: '聊一聊'
            },
            component: resolve => (require(["@/views/chat"], resolve)),//聊一聊
        },
        {
            path: '/orderDetail/:id/:issueId',
            name: 'orderDetail',
            meta: {
                title: '订单详情'
            },
            component: resolve => (require(["@/views/orderDetail"], resolve)),//订单详情
        },
        {
            path: '/userCenter',
            name: 'userCenter',
            meta: {
                title: '我的'
            },
            component: resolve => (require(["@/views/userCenter"], resolve)),//个人中心
        },
        {
            path: '/list/:type',
            name: 'list',
            meta: {
                title: '列表'
            },
            component: resolve => (require(["@/views/list"], resolve)),//列表
        },
        {
            path: '/contactUs',
            name: 'contactUs',
            meta: {
                title: '联系我们'
            },
            component: resolve => (require(["@/views/contactUs"], resolve)), //联系我们
        },
        {
            path: '/messageDetail/:content',
            name: 'messageDetail',
            meta: {
                title: '系统消息详情'
            },
            component: resolve => (require(["@/views/message-detail.vue"], resolve)), //系统消息详情
        },
        
        // {
        //     path: '/review/:id',
        //     name: 'review',
        //     meta: {
        //         title: '评价订单'
        //     },
        //     component: resolve => (require(["@/views/review"], resolve)), //评价订单
        // },
        // {
        //     path: '/reviewList',
        //     name: 'reviewList',
        //     meta: {
        //         title: '评价订单'
        //     },
        //     component: resolve => (require(["@/views/reviewList"], resolve)), //我的评价
        // },
        // {
        //     path: '/glabOrder/:id',
        //     name: 'glabOrder',
        //     meta: {
        //         title: '抢单'
        //     },
        //     component: resolve => (require(["@/views/glabOrder"], resolve)), //抢单-详情
        // },
        // {
        //     path: '/orderDetail',
        //     name: 'orderDetail',
        //     meta: {
        //         title: '订单详情'
        //     },
        //     component: resolve => (require(["@/views/orderDetail"], resolve)), //平台-订单详情
        // },
        // {
        //     path: '/orderGiveup',
        //     name: 'orderGiveup',
        //     meta: {
        //         title: '订单详情'
        //     },
        //     component: resolve => (require(["@/views/orderGiveup"], resolve)), //平台-已取消订单详情
        // },
        // {
        //     path: '/glabOrderList',
        //     name: 'glabOrderList',
        //     meta: {
        //         title: '待完成'
        //     },
        //     component: resolve => (require(["@/views/glabOrderList"], resolve)), //快递员-待完成订单
        // },
        {
            path: '/verify',
            name: 'verify',
            meta: {
                title: '实名认证'
            },
            component: resolve => (require(["@/views/verify"], resolve)), //快递员-实名认证
        },
        {
            path: '/verifyList',
            name: 'verifyList',
            meta: {
                title: '我的认证'
            },
            component: resolve => (require(["@/views/verifyList"], resolve)), //我的认证
        },
    
        
      
        //登录
        {
            path: '/Login',
            name: 'Login',
            meta: {
                title: '登录'
            },
            component: resolve => (require(["@/views/Login"], resolve)),
        },
             //注册
             {
                path: '/register',
                name: 'register',
                meta: {
                    title: '注册'
                },
                component: resolve => (require(["@/views/register"], resolve)),
            },
       
       
        //修改密码
        {
            path: '/userProfile',
            name: 'userProfile',
            meta: {
                title: '修改密码'
            },
            component: resolve => (require(["@/views/userProfile"], resolve)),
        },
       
        
        
        


    ]
});


Vue.use(Router)

//在路由跳转的时候同一个路由多次添加是不被允许的
//重写路由的push方法
const VueRouterPush = Router.prototype.push
Router.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch(err => err)
}


const _arr = ['index'];
//  判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => {

    var index = _arr.indexOf(to.name);
    if (index !== -1) {
        //如果存在路由列表，则把之后的路由都删掉
        _arr.splice(index + 1, _arr.length - index - 1);
        store.state.crumb.splice(index + 1, store.state.crumb.length - index - 1);
    } else {
        _arr.push(to.name);
        store.state.crumb.push(to)
    }
    to.meta.routeList = store.state.crumb
    next()
})
export default router;